package com.dawn.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

public class PropertiesTools {

    private static Logger logger = Logger.getLogger(PropertiesTools.class);

    private static Properties properties;
    private static PropertiesTools instance = new PropertiesTools();
    
    public static PropertiesTools getInstance() {
        return instance;
    }

    private PropertiesTools() {
        InputStream in = null;
        Properties pro = new Properties();
        try {
            System.out.println("ceshi~~~~~~~~~~~~~~~~~~~~~");
            in = PropertiesTools.class.getClassLoader().getResourceAsStream("sys.properties");
            pro.load(in);
            PropertiesTools.properties = pro;
        } catch (Exception e) {
            logger.error("装载配置文件sys.properties出现异常", e);
        } finally {
            if (null != in)
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
        }
    }

    /*
     * 根据key读取value
     */
    public String getProperty(String key) throws IOException {
        return properties.getProperty(key);
    }
    
    public static void main(String args[]) throws IOException{
        System.out.println(PropertiesTools.getInstance().getProperty("call_back_url"));
    }

}
